#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <linux/in.h>

#define PORT 8888
void process_conn_client(int);
int main()
{
	int s;
	struct sockaddr_in server;
	int err;	
	s = socket(AF_INET, SOCK_STREAM , 0);
	if( s<0 )
	{
		printf("socket error");
		return -1;
	}
	
	bzero(&server,sizeof(server));
	server.sin_family =AF_INET;
	server.sin_addr.s_addr = htonl(INADDR_ANY);
	server.sin_port = htons(PORT);
	
	connect(s , (struct sockaddr*)&server , sizeof(server));
	
	process_conn_client(s);
	close(s);
}


void process_conn_client(int s)
{	
	ssize_t size = 0;
	char buffer[1024];
	while(1)
	{
		size = read(0,buffer , 1024);
		if(size>0)
		{
			write(s,buffer,size);
			size = read(s,buffer,1024);
			write(1,buffer,size);
		}
	}
}
